#!/bin/sh
# set -v

HOST=arm-linux-gnueabihf
SCRIPT_PATH=$(pwd)

# 脚本是mk 脚本调过来的 环境变量在mk里面已经 export过了这里可以不用再次export
# export PATH=$PATH:$SCRIPT_PATH/../../toolchains/gcc_aarch64_11/bin # 将工具链添加到环境变量   仅本shell生效
CROSS_CHAIN_PREFIX=aarch64-none-linux-gnu
#修改源码包解压后的名称
MAJOR_NAME=tslib

#定义编译后安装--生成的文件,文件夹位置路径
INSTALL_PATH=$1
#mkdir -p ${INSTALL_PATH}

#下载源码包
do_download_src () {
   echo "\033[33m start download ${MAJOR_NAME}...\033[0m"

    if [ ! -d "${MAJOR_NAME}" ];then
        git clone https://gitee.com/leeboby/tslib.git
    fi
   echo "\033[33m done...\033[0m"
}

#配置选项
do_configure_make () {
   echo "\033[33m start configure ${MAJOR_NAME}...\033[0m"

   export CC=${CROSS_CHAIN_PREFIX}-gcc
   cd ${MAJOR_NAME}
   ./autogen.sh
   echo "\033[33m install ${INSTALL_PATH}...\033[0m"
   ./configure --prefix=${INSTALL_PATH} --host=${HOST}
   make && make install
   cd -
   echo "\033[33m done...\033[0m"
}

#删除下载的文件
do_delete_file () {
   cd ${SCRIPT_PATH}
   if [ -d "${MAJOR_NAME}" ];then
      sudo rm -f ${MAJOR_NAME}
   fi
}

do_download_src
do_configure_make
# do_delete_file

exit $?